package com.spzx.user.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.user.api.RemoteUserInfoService;
import com.spzx.user.api.domain.UpdateUserLogin;
import com.spzx.user.api.domain.UserInfo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author Haoran Sun
 * @since 2024/07/29
 */

@Component
public class RemoteUserInfoFallbackFactory implements FallbackFactory<RemoteUserInfoService> {
    @Override
    public RemoteUserInfoService create(Throwable cause) {
        return new RemoteUserInfoService() {
            @Override
            public R<Boolean> register(UserInfo userInfo, String source) {
                return R.fail("用户注册服务远程调用失败：" +  cause.getMessage());
            }

            @Override
            public R<UserInfo> getUserInfo(String username, String source) {
                return R.fail("根据用户名获取用户信息服务远程调用失败：" +  cause.getMessage());
            }

            @Override
            public R<Boolean> updateUserLogin(UpdateUserLogin updateUserLogin, String source) {
                return R.fail("更新用户登录信息服务远程调用失败：" +  cause.getMessage());
            }
        };
    }
}
